import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useTemplateStore = defineStore('template', () => {
  // 表单默认值
  const defaultForm = ref({
    name: '',
    type: 'curve',
    author: localStorage.getItem('lastAuthor') || '',
    note: ''
  })

  // 消息提示配置
  const messageConfig = {
    duration: 5000,  // 消息显示时间
    showClose: true  // 显示关闭按钮
  }

  // 更新作者信息
  const updateAuthor = (author) => {
    defaultForm.value.author = author
    localStorage.setItem('lastAuthor', author)
  }

  // 重置表单
  const resetForm = () => {
    defaultForm.value = {
      name: '',
      type: 'curve',
      author: localStorage.getItem('lastAuthor') || '',
      note: ''
    }
  }

  return {
    defaultForm,
    messageConfig,
    updateAuthor,
    resetForm
  }
}) 